package com.market.dao;


import java.io.Serializable;
import java.util.List;

import javax.persistence.EntityManager;

import com.market.domain.BaseObject;



public interface GenericDao <BO extends BaseObject, PK extends Serializable> {
	
	 
	 public EntityManager getEntityManager();
	 
	 
	 /**
	  * Get all entities of specific type from databases;
	  * This operation only load those basic properties, associated entities will not be loaded.
	  * @return
	  */
	 
	 public List<BO> findAll();
	 



    /**
     *Load the entity that is specified by id from database
     *This operation will  only load basic properties.
     */
	 public BO findById(PK id);

    /**
     * Check if the entity that is specified by id is exist in database.
     */
    boolean existsById(PK id);

    /**
	 * This operation will update the record already in database
	 * Find the record by id
	 */
	public BO merge(BO object);	
	
	
	/**
	 * This method save new object in to database
	 * This method will generate new id if it need, and set object's isNew property to false;
	 */

	public BO persist(BO object); 
	
	
	/**
	 * This method will persist new object into database if not exist in database, and set isNew property to false;
	 * Or merge the object into database if it's already exist in database;
	 */
	
	public BO save(BO object);	
	
	
	/**
	 * This method remove entity object from database
	 * The entity object is specified by id
	 * @param object
	 * @return
	 */
	public void removeById(PK id) ;
	
	/**
	 * This method remove entity object from database
	 * The entity object is specified by entity object, not an id
	 * @param object
	 * @return
	 */
	public void remove(BO object) ;
	
}